package com.gongpingjialoan.widget;

import com.gongpingjialoan.R;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ConfirmDialog extends Dialog {

	private ConfirmDialog mySelf = this;
	Context context;
	private Handler messageHanlder;
	private Button yes_layout;
	private Button no_layout;
	private TextView tips_txt;
	private String msg;
	
	public ConfirmDialog(Context context,String msg,Handler messageHanlder) {
		super(context,R.style.dialogs);
		this.context = context;
		this.messageHanlder = messageHanlder;
		this.msg = msg;
	}

    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.confirm_dialog);
        this.setCanceledOnTouchOutside(false);
        yes_layout = (Button)this.findViewById(R.id.yes_btn);
        no_layout = (Button)this.findViewById(R.id.no_btn);
        tips_txt = (TextView)this.findViewById(R.id.tips_txt);
        tips_txt.setText(msg);
        yes_layout.setOnClickListener(new android.view.View.OnClickListener() {
			public void onClick(View v) {
				if(messageHanlder != null){
					Message msg = new Message();
					msg.what = 1;
					messageHanlder.sendMessage(msg);
				}
				mySelf.dismiss();
			}
		});
        no_layout.setOnClickListener( new android.view.View.OnClickListener() {
			public void onClick(View v) {
				if(messageHanlder != null){
					Message msg = new Message();
					msg.what = 2;
					messageHanlder.sendMessage(msg);
				}
				mySelf.dismiss();
			}
		});
        mySelf.setCanceledOnTouchOutside(true);
    }
}
